]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
user-status: Hide "Power off" option if shutdown is disabled
authorFlorian Müllner <fmuellner@gnome.org>
Fri, 3 Jun 2011 22:10:55 +0000 (00:10 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Mon, 27 Jun 2011 19:39:28 +0000 (21:39 +0200)
Due to lockdown settings or Polkit policy, shutdown may not be
available. If this is the case, the "Power off ..." action should
be hidden from the user status menu.

https://bugzilla.gnome.org/show_bug.cgi?id=652038

js/misc/gnomeSession.js
js/ui/statusMenu.js

index 1a52a6f4b6602fb06efa7d6c26cb88789c5b8f74..c661d4140c99e3b300e674c8917206edcaab785c 100644 (file)
@@ -109,7 +109,8 @@ const SessionManagerIface = {
     name: 'org.gnome.SessionManager',
     methods: [
         { name: 'Logout', inSignature: 'u', outSignature: '' },
-        { name: 'Shutdown', inSignature: '', outSignature: '' }
+        { name: 'Shutdown', inSignature: '', outSignature: '' },
+        { name: 'CanShutdown', inSignature: '', outSignature: 'b' }
     ]
 };
 
index b778d1f0896edac792302d0e427d6e87df55e7c9..7d49743aec8cf9d262e46b75e7c7da58995f4c3c 100644 (file)
@@ -58,6 +58,7 @@ StatusMenuButton.prototype = {
         this._presence = new GnomeSession.Presence();
         this._presenceItems = {};
         this._session = new GnomeSession.SessionManager();
+        this._haveShutdown = true;
 
         this._account_mgr = Tp.AccountManager.dup()
 
@@ -90,12 +91,25 @@ StatusMenuButton.prototype = {
                                        Lang.bind(this, this._updateSwitchUser));
         this._lockdownSettings.connect('changed::' + DISABLE_LOG_OUT_KEY,
                                        Lang.bind(this, this._updateLogout));
+
         this._lockdownSettings.connect('changed::' + DISABLE_LOCK_SCREEN_KEY,
                                        Lang.bind(this, this._updateLockScreen));
         this._updateSwitchUser();
         this._updateLogout();
         this._updateLockScreen();
 
+        // Whether shutdown is available or not depends on both lockdown
+        // settings (disable-log-out) and Polkit policy - the latter doesn't
+        // notify, so we update the menu item each time the menu opens or
+        // the lockdown setting changes, which should be close enough.
+        this.menu.connect('open-state-changed', Lang.bind(this,
+            function(menu, open) {
+                if (open)
+                    this._updateHaveShutdown();
+            }));
+        this._lockdownSettings.connect('changed::' + DISABLE_LOG_OUT_KEY,
+                                       Lang.bind(this, this._updateHaveShutdown));
+
         this._upClient.connect('notify::can-suspend', Lang.bind(this, this._updateSuspendOrPowerOff));
     },
 
@@ -112,13 +126,25 @@ StatusMenuButton.prototype = {
     },
 
     _updateSessionSeparator: function() {
-        let showSeparator = this._loginScreenItem.actor.visible ||
-                            this._logoutItem.actor.visible ||
-                            this._lockScreenItem.actor.visible;
-        if (showSeparator)
+        let sessionItemsVisible = this._loginScreenItem.actor.visible ||
+                                  this._logoutItem.actor.visible ||
+                                  this._lockScreenItem.actor.visible;
+
+        let showSessionSeparator = sessionItemsVisible &&
+                                   this._suspendOrPowerOffItem.actor.visible;
+
+        let showSettingsSeparator = sessionItemsVisible ||
+                                    this._suspendOrPowerOffItem.actor.visible;
+
+        if (showSessionSeparator)
             this._sessionSeparator.actor.show();
         else
             this._sessionSeparator.actor.hide();
+
+        if (showSettingsSeparator)
+            this._settingsSeparator.actor.show();
+        else
+            this._settingsSeparator.actor.hide();
     },
 
     _updateSwitchUser: function() {
@@ -148,16 +174,34 @@ StatusMenuButton.prototype = {
         this._updateSessionSeparator();
     },
 
+    _updateHaveShutdown: function() {
+        this._session.CanShutdownRemote(Lang.bind(this,
+            function(result, error) {
+                if (!error) {
+                    this._haveShutdown = result;
+                    this._updateSuspendOrPowerOff();
+                }
+            }));
+    },
+
     _updateSuspendOrPowerOff: function() {
         this._haveSuspend = this._upClient.get_can_suspend();
 
         if (!this._suspendOrPowerOffItem)
             return;
 
+        if (!this._haveShutdown && !this._haveSuspend)
+            this._suspendOrPowerOffItem.actor.hide();
+        else
+            this._suspendOrPowerOffItem.actor.show();
+         this._updateSessionSeparator();
+
         // If we can't suspend show Power Off... instead
         // and disable the alt key
         if (!this._haveSuspend) {
             this._suspendOrPowerOffItem.updateText(_("Power Off..."), null);
+        } else if (!this._haveShutdown) {
+            this._suspendOrPowerOffItem.updateText(_("Suspend"), null);
         } else {
             this._suspendOrPowerOffItem.updateText(_("Suspend"), _("Power Off..."));
         }
@@ -203,6 +247,7 @@ StatusMenuButton.prototype = {
 
         item = new PopupMenu.PopupSeparatorMenuItem();
         this.menu.addMenuItem(item);
+        this._settingsSeparator = item;
 
         item = new PopupMenu.PopupMenuItem(_("Lock Screen"));
         item.connect('activate', Lang.bind(this, this._onLockScreenActivate));